package cumeo89.chii.client.entry.edit;

import com.google.gwt.xml.client.Element;

import cumeo89.chii.client.entry.EntryModel;
import cumeo89.chii.client.undo.UndoableEdit;

public class SetAttrEdit implements UndoableEdit {

	private Element element;
	private String name;
	private String newValue;
	private EntryModel model;

	public SetAttrEdit(EntryModel model, Element element, String name,
			String newValue) {
		this.element = element;
		this.name = name;
		this.newValue = newValue;
		this.model = model;
	}

	public void redo() {
		swapValue();
	}

	public void undo() {
		swapValue();
	}

	private void swapValue() {
		String t = element.getAttribute(name);
		model.setAttribute(element, name, newValue);
		newValue = t;
	}

}
